package cn.dengta.webapp.trade.entity;

import java.math.BigDecimal;
import java.util.Date;

import cn.dengta.common.model.Status;
import cn.dengta.common.model.SwitchSupport;
import cn.dengta.webapp.base.entity.BizEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 充值全额返
 *
 * @author lgy
 * @since 2022-09-08
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("act_double_recharge")
public class ActDoubleRecharge extends BizEntity implements SwitchSupport {

	/** 用户ID */
	private Long userId;
	/** 本次充值的钻石数 */
	private Integer coin;
	/** 免费赠送的钻石数（不含VIP免费赠送数） */
	private Integer freeCoin;
	/** 商品价格 */
	private BigDecimal price;
	/** 实际支付总额 */
	private BigDecimal realPay;
	/** 本次奖励的钻石数 */
	private Integer calcCoin;
	/** 本次奖励总钻石数 */
	private Integer totalCoin;
	/** 可领取次数 */
	private Integer limitTimes;
	/** 已领取次数 */
	private Integer received;
	/** 已领取钻石 */
	private Integer receivedCoin;
	/** 开始时间 */
	private Date beginTime;
	/** 结束时间 */
	private Date endTime;
	/** 规则JSON配置 */
	private String config;
	/** 充值记录ID */
	private Long rechargeLogId;

	public ActDoubleRecharge init(Integer limitTimes, Date beginTime, Date endTime, String config, RechargeLog log, Date now) {
		this.userId = log.getUserId();
		this.coin = log.getCoin();
		this.freeCoin = log.getFreeCoin();
		this.price = log.getPrice();
		this.realPay = log.getRealPay();
		this.calcCoin = log.getCoin();
		this.limitTimes = limitTimes;
		this.received = 0;
		this.receivedCoin = 0;
		this.beginTime = beginTime;
		this.endTime = endTime;
		this.config = config;
		this.rechargeLogId = log.getId();
		super.initActiveStatus();
		super.initTime(now);
		return this;
	}

	public boolean canSettle() {
		return Status.asResult(status);
	}

	public boolean canReceive() {
		return received < limitTimes;
	}

	public boolean isReceive() {
		return receivedCoin > 0;
	}

	public static final String USER_ID = "user_id";
	public static final String COIN = "coin";
	public static final String FREE_COIN = "free_coin";
	public static final String PRICE = "price";
	public static final String REAL_PAY = "real_pay";
	public static final String CALC_COIN = "calc_coin";
	public static final String TOTAL_COIN = "total_coin";
	public static final String LIMIT_TIMES = "limit_times";
	public static final String RECEIVED = "received";
	public static final String RECEIVED_COIN = "received_coin";
	public static final String BEGIN_TIME = "begin_time";
	public static final String END_TIME = "end_time";
	public static final String CONFIG = "config";
	public static final String RECHARGE_LOG_ID = "recharge_log_id";

}
